home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7383 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  63 lines

  1. Path: newshost.comco.com!not-for-mail
  2. From: sharma@comco.com (Sharma)
  3. Newsgroups: comp.lang.c++
  4. Subject: Template instantiation and inlining
  5. Date: 22 Feb 1996 16:50:30 -0600
  6. Organization: Computational Mechanics, Inc.
  7. Distribution: usa
  8. Message-ID: <4girvm$6eg@sphinx.comco.com>
  9. NNTP-Posting-Host: sphinx.comco.com
  10.  
  11. In order to prevent multiple instantiations of templated classes (for
  12. similar parameter types), I want to use explicit instantiations. I
  13. want to place these explicit instantiations in a separate file and let
  14. the actual source files using templated classes 'see' the definition
  15. of the templated classes. What is not clear to me is if the member
  16. functions declared inlined (and defined in header file) will actually
  17. get inlined in the source file using them, if implicit template
  18. instantiation is turned off (can be done in gcc) ?
  19.  
  20. Consider this example:
  21.  
  22. file foo.h
  23. ----------
  24.  
  25. template <class T>
  26. class foo {
  27.  inline do_something() {...};
  28.  other_functions (defined in foo.C);
  29. }
  30.  
  31. file foo-inst.C
  32. ---------------
  33. #include "foo.h"
  34. #include "foo.C"
  35.  
  36. template class foo<int>;
  37. template class foo<double>;
  38.  
  39. Compilation of foo-inst.C will instantiate various foo classes
  40. (exactly once).
  41.  
  42. file main.C
  43. -----------
  44. #include "foo.h"
  45.  
  46. void main ()
  47. {
  48.  foo<int> a;
  49.  foo<double> b;
  50.  
  51.  a.do_something();
  52.  b.do_something();
  53. }
  54.  
  55. Question is: will do_something() be inlined in main, if implicit
  56. instantiation of foo is suppressed here (during compilation) ?
  57.  
  58. A more general question would be whether inlining of member methods is
  59. possible without instantiation of the class itself ?
  60.  
  61.  
  62. Suresh
  63.